#include "stdafx.h"
#include "GeoDrill.h"
#include "dmEntityBase.h"
#include "GeoDrillData.h"
#include "DbDatabase.h"

#include "GeoBlkData.h"

dmGeoDrillDataCS::dmGeoDrillDataCS()
{
	Native=CGeoDrillData::New();
}
bool dmGeoDrillDataCS::Save(STRINGCS filename)
{
	VALIDATE_NATIVE
	String2Char(filename)
	return m_native->Save(fn);
}

bool dmGeoDrillDataCS::Load(STRINGCS filename)
{
	VALIDATE_NATIVE
	String2Char(filename)
	return m_native->Load(fn);
}
bool dmGeoDrillDataCS::Load(dmDbDatabaseCS db)
{
	VALIDATE_NATIVE
	return m_native->Load(db.Native);
}
List<STRINGCS>^ dmGeoDrillDataCS::GetHoleNameSet()
{
	List<STRINGCS>^ ret=gcnew List<STRINGCS>();
	if(!m_native) return ret;
	std::set<std::string> sets;
	if(m_native->GetHoleNameSet(sets))
	{
		std::set<std::string>::const_iterator begin=sets.begin();
		std::set<std::string>::const_iterator end=sets.end();
		while(begin!=end)
		{
			ret->Add(gcnew System::String(begin->c_str()));
			++begin;
		}
		return ret;
	}
	return ret;
}

dmDataTableCS^ dmGeoDrillDataCS::GetCollarTable()
{
	if(!m_native) return nullptr;
	return gcnew dmDataTableCS(m_native->GetCollarTable());
}

dmDataTableCS^ dmGeoDrillDataCS::GetSurveyTable()
{
	if(!m_native) return nullptr;
	return gcnew dmDataTableCS(m_native->GetSurveyTable());
}

dmDataTableCS^ dmGeoDrillDataCS::GetSampleTable()
{
	if(!m_native) return nullptr;
	return gcnew dmDataTableCS(m_native->GetSampleTable());
}

dmDataTableCS^ dmGeoDrillDataCS::GetLithologyTable()
{
	if(!m_native) return nullptr;
	return gcnew dmDataTableCS(m_native->GetLithologyTable());
}

array<double>^ dmGeoDrillDataCS::GetBounds()
{
	if(!m_native) return nullptr;
	double bounds[6];
	m_native->GetBounds(bounds);
	array<double>^ rets=gcnew array<double>(6);
	for(int i=0;i<6;i++)
	{
		rets[i]=bounds[i];
	}
	return rets;
}

bool dmGeoDrillDataCS::Remove()
{
	VALIDATE_NATIVE
	return m_native->Remove();
}
bool dmGeoDrillDataCS::Remove(bool bSave,STRINGCS filename)
{
	VALIDATE_NATIVE
	String2Char(filename)
	return m_native->Remove(bSave,fn);
}
List<STRINGCS>^ dmGeoDrillDataCS::GetItemNames()
{
	List<STRINGCS>^ ret=gcnew List<STRINGCS>();
	if(!m_native) return ret;
	std::vector<std::string> items;
	if(m_native->GetItemName(items)==DM::eOk)
	{
		std::vector<std::string>::const_iterator begin=items.begin();
		std::vector<std::string>::const_iterator end=items.end();
		while(begin!=end)
		{
			ret->Add(gcnew System::String(begin->c_str()));
			++begin;
		}
		return ret;
	}
	return ret;
}